package com.tff.demo.controller;


import com.tff.demo.pojo.User;
import com.tff.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.websocket.server.PathParam;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;



@RestController
public class UserContorller {



    @Autowired
    private UserService userService;

    @RequestMapping("/test")
    public Map<String,String> testMethod(){
        Map<String,String> map = new HashMap<>();
        map.put("name","list");
        map.put("age","16");
        return map;
    }

    /***
     * 插入用户
     * @return
     */
    @GetMapping("/insertUser")
    public Map<String,String> insertUser(){
        Map<String,String> map = new HashMap<>();
        User user = new User();
        user.setUserName("王亚楠");
        user.setPassWord("wangyanan");
        user.setAge(26);
        user.setTel("123456789");
        int res = userService.insertUser(user);
        if(res>0){
            map.put("status","天假成功");
        }else {
            map.put("status","插入失败");
        }

        return map;
    }
    @RequestMapping(value = "/getUser/{username}")
    public Map<String,String> getUserByUserName(@PathParam("username") String username){
        Map<String,String> user = new HashMap<>();
        User user1 = userService.selectUserOne(username);
        user.put("ID: ",(user1.getId()+"").toString());
        user.put("username: ",user1.getUserName());
        user.put("password: ",user1.getPassWord());
        user.put("tel: ",user1.getTel());
        if(user1 == null || user.equals("")){
            user.put("status","用户名不存在");
        }
        return user;
    }

}
